package com.suncaper.han_yi_system.config;

import com.suncaper.han_yi_system.ai.AITools;
import com.suncaper.han_yi_system.ai.SMSConstants;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {

    @Bean
    public ChatMemory chatMemory() {
        return MessageWindowChatMemory.builder()
                .maxMessages(20)
                .build();
    }

    @Bean
    public ChatClient chatClient(ChatModel chatModel, ChatMemory chatMemory, AITools aiTools) {
        return ChatClient.builder(chatModel).defaultSystem(SMSConstants.WARM_CLOTHING_ASSISTANT)
                .defaultAdvisors(new SimpleLoggerAdvisor(), MessageChatMemoryAdvisor.builder(chatMemory).build()) // 1. 配置日志 2. 配置会话记录
                .defaultTools(aiTools) // 绑定工具
                .build();
    }

}
